package com.odm.communitymanage.ui.mine.MyPay

import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.entity.node.BaseExpandNode
import com.chad.library.adapter.base.entity.node.BaseNode
import com.google.gson.Gson
import com.odm.communitymanage.R
import com.odm.communitymanage.base.BaseFragment
import com.odm.communitymanage.core.bean.MonthExpense
import com.odm.communitymanage.core.bean.MyExpenses
import com.odm.communitymanage.core.bean.TypeExpense
import kotlinx.android.synthetic.main.fragment_my_pay.*

/**
 * @description: 我的缴费（支付）
 * @author: ODM
 * @date: 2020/4/20
 */
class MyPayFragment : BaseFragment(){


    private var rvPayedAdapter : MyPayAdapter ?= null
    private var rvUnPayedAdapter : MyPayAdapter ?= null

    override fun initViews() {
        ivBack_MyPay?.setOnClickListener { 
            pop()
        }
        rvPayedAdapter = MyPayAdapter()
        rvPayed.layoutManager = LinearLayoutManager(activity)
        rvPayed.adapter = rvPayedAdapter
        rvPayedAdapter?.animationEnable = true
        rvPayedAdapter?.setAnimationWithDefault(BaseQuickAdapter.AnimationType.SlideInBottom)


        rvUnPayedAdapter = MyPayAdapter()
        rvUnPay.layoutManager = LinearLayoutManager(activity)
        rvUnPay.adapter = rvUnPayedAdapter
        rvUnPayedAdapter?.animationEnable = true
        rvUnPayedAdapter?.setAnimationWithDefault(BaseQuickAdapter.AnimationType.SlideInBottom)

        createFakeMyPayData()
    }

    private fun  collapseAllItem(){
        rvPayedAdapter?.let {
            var size : Int = it.data.size
            while (size-- > 0){
                it.collapse(size)
            }
        }
        rvUnPayedAdapter?.let {
            var size : Int = it.data.size
            while (size-- > 0){
                it.collapse(size)
            }
        }
    }

    /**
     * 创造假数据 树状列表
     */
    private fun createFakeMyPayData(){
        var fakeData : MyExpenses = GsonUtils.fromJson( "{\"code\":\"1\",\"msg\":\"success\",\"MonthExpenses\":[{\"sum\":\"900.00\",\"time\":\"2020年3月\",\"typeExpenses\":[{\"price\":\"405.00\",\"type\":\"电费\"},{\"price\":\"295.00\",\"type\":\"物业管理费\"},{\"price\":\"100.00\",\"type\":\"燃气费\"},{\"price\":\"100.00\",\"type\":\"水费\"}]},{\"sum\":\"700.00\",\"time\":\"2020年2月\",\"typeExpenses\":[{\"price\":\"305.00\",\"type\":\"电费\"},{\"price\":\"195.00\",\"type\":\"物业管理费\"},{\"price\":\"100.00\",\"type\":\"燃气费\"},{\"price\":\"100.00\",\"type\":\"水费\"}]},{\"sum\":\"700.00\",\"time\":\"2020年1月\",\"typeExpenses\":[{\"price\":\"305.00\",\"type\":\"电费\"},{\"price\":\"195.00\",\"type\":\"物业管理费\"},{\"price\":\"100.00\",\"type\":\"燃气费\"},{\"price\":\"100.00\",\"type\":\"水费\"}]}]}",
            MyExpenses::class.java)
        val payed : MutableList<BaseNode>  = fakeData.monthExpenses.toMutableList() as MutableList<BaseNode>
        rvPayedAdapter?.setNewData(payed)
        fakeData  = GsonUtils.fromJson( "{\"code\":\"1\",\"msg\":\"success\",\"MonthExpenses\":[\n" +
                "{\"sum\":\"700.00\",\"time\":\"2020年4月\",\"typeExpenses\":[{\"price\":\"205.00\",\"type\":\"电费\"},{\"price\":\"295.00\",\"type\":\"物业管理费\"},{\"price\":\"100.00\",\"type\":\"燃气费\"},{\"price\":\"100.00\",\"type\":\"水费\"}]}\n" +
                "]}",
            MyExpenses::class.java)
        val unpayed  : MutableList<BaseNode>  = fakeData.monthExpenses.toMutableList() as MutableList<BaseNode>
        rvUnPayedAdapter?.setNewData(unpayed)

        var unPaySum = 700.00
        tvUnPay_MyPay?.text = unPaySum.toString()

        //本月产生费用
        tvNeedPay_MyPay?.text = "425.50"

    }
    
    
    

    override fun getLayoutId(): Int {
        return R.layout.fragment_my_pay
    }
    
    
    
}